#include <vector>
#include <string>
#include <unordered_map>

using namespace std;

class Solution
{
public:
    vector<string> commonChars(vector<string> &words)
    {
        vector<string> ret;
        if (words.size() == 0)
        {
            return ret;
        }
        vector<unordered_map<char, int>> v;
        for (const auto &e : words)
        {
            unordered_map<char, int> tmp;
            for (auto w : e)
            {
                tmp[w]++;
            }
            v.push_back(move(tmp));
        }

        for (int i = 0; i < words[0].size(); ++i)
        {
            bool flag = true;
            for (auto e : v)
            {
                if (e[words[0][i]]-- == 0)
                {
                    flag = false;
                    break;
                }
            }
            if (flag)
            {
                ret.push_back({words[0][i]});
            }
        }
        return ret;
    }
};